﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using snat.model;

namespace gui {

    /// <summary>
    /// GUI Notifiable MessageItem Class
    /// Message Item holds a message, a target and source node,
    /// timestamp and a body property
    /// </summary>
    public class MessageItem : IComparable {
        public MessageItem(Message m, BaseNode target) {
            Msg = m;
            Source = m.Sender.Name;
            if (target != null) Target = target.Name;
            else Target = "Unknown";
            Timestamp = m.Timestamp;
            Body = m.Data;
        }

        public MessageItem(Message m, string target) {
            Msg = m;
            Source = m.Sender.Name;
            if (target != null) Target = target;
            else Target = "Unknown";
            Timestamp = m.Timestamp;
            Body = m.Data;
        }

        public Message Msg { set; get; }
        public string Source { set; get; }
        public string Target { set; get; }
        public DateTime Timestamp { set; get; }
        public string Body { set; get; }

        public override string ToString() {
            return "Message From: " + Source + " To: " + Target + " Body: " + Body;
        }

        public int CompareTo(object obj) {
            MessageItem m = (MessageItem)obj;
            if ( this.Timestamp > m.Timestamp)
            return 1;
            if (this.Timestamp < m.Timestamp)
                return -1;
            else
                return 0;
        }
    }
}
